package entity;

public class NetPackage extends BrandPackage implements NetService{//网卡套餐类
    private int flow = 3072;

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }

    public NetPackage(double price, int flow) {
        super(price);
        this.flow = flow;
    }

    public NetPackage() {
    }

    @Override
    public void show() {
        System.out.println("网虫套餐：上网流量" + flow + "MB");
    }

    @Override
    public int netPlay(int flow, MobileCard card) throws Exception {
        int tempFlow = 0;
        for (int i = 0; i < flow; i++) {
            tempFlow++;
            if ((this.flow - card.getRealFlow()) >= 1) {
                card.setRealFlow(card.getRealFlow() + 1);
            }else if (card.getMoney() >= 0.1) {
               card.setMoney(card.getMoney() - 0.1);
                card.setRealFlow(card.getRealFlow() + 1);
                card.setConsume(card.getConsume() + 0.1);
            }else {
                throw new Exception("本次上网已用" + tempFlow + "MB流量，余额不足请立即充值");
            }
        }
        return tempFlow;
    }
}
